package com.zdd.ehe.controller;

import com.zdd.ehe.entity.Log;
import com.zdd.ehe.result.Result;
import com.zdd.ehe.service.ILogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZhuiZhu
 * @since 2023-04-20
 */
@Api(tags = "日志模块")
@RestController
@RequestMapping("/log")
public class LogController {
    @Resource
    private ILogService logService;

    @ApiOperation("查询日志接口")
    @GetMapping("/queryLog")
    public Result queryLog(){
        List<Log> logList = logService.queryLog();
        return Result.success("查询成功",logList);
    }

    @ApiOperation("新增日志接口")
    @PostMapping("/insertLog")
    public Result insertLog(@RequestBody Log log){
        log.setStatus("1");
        log.setTime(LocalDateTime.now());
        int result = logService.insertLog(log);
        if(result != 1 ){
            return Result.error("新增失败");
        }
        return Result.success("新增成功");
    }

}
